<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>GoMD - admin！ </title>
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon"/>
    <link rel="icon" href="/favicon.ico" type="image/x-icon"/>
    <meta name="keywords" content="GoMD,xuthus,go,golang,beego,Simple">
    <meta name="description" content="GoMD 是一个基于beego框架构建的一个轻量，简约的博客项目，帮您快速构建博客。">
    <link rel="stylesheet" href="/static/admin/css/s.css">
    <link rel="stylesheet" href="/static/admin/css/extend.css">
    <script src="/static/common/layui/layui.js"></script>
</head>
<body>

<link rel="stylesheet" href="/static/admin/css/login.css">

<div class="layui-container">
    <div class="layui-row">
        <div class="layui-col-md3 layui-col-md-offset9">
            <div class="loginbox">
                <div class="loginbox-header">
                    <h3>欢迎，GoMD！</h3>
                </div>
                <form action="" class="layui-form" method="post">
                    <div class="layui-row layui-form-item">
                        <div class="layui-col-md12">
                            <div class="layui-input-block no-label">
                                <label class="input-icon layui-icon layui-icon-username" for="username"></label>
                                <input type="text" name="username" id="username" lay-verify="required"
                                       placeholder="用户名" class="layui-input">
                            </div>
                        </div>
                    </div>
                    <div class="layui-row  layui-form-item">
                        <div class="layui-col-md12">
                            <div class="layui-input-block no-label">
                                <label class="input-icon layui-icon layui-icon-password" for="password"></label>
                                <input type="password" name="password" id="password" lay-verify="required"
                                       placeholder="密码" class="layui-input">
                            </div>
                        </div>
                    </div>

                    <div class="layui-form-item loginbox-check">
                        <input type="checkbox" name="remember" lay-skin="primary" title="记住密码" value="1">
                        <div class="layui-unselect layui-form-checkbox" lay-skin="primary"><span>记住密码</span><i
                                class="layui-icon layui-icon-ok"></i></div>
                    </div>

                    <div class="layui-form-item">
                        <button class="layui-btn layui-btn-fluid" lay-submit lay-filter="login">登 入</button>
                    </div>
                    <div class="layui-form-item loginbox-other">
                        <label>社交账号登入</label>
                        <a href="javascript:;"><i class="layui-icon layui-icon-login-qq"></i></a>
                        <a href="javascript:;"><i class="layui-icon layui-icon-login-wechat"></i></a>
                        <a href="javascript:;"><i class="layui-icon layui-icon-login-weibo"></i></a>
                    </div>
                </form>

            </div>

        </div>
    </div>
</div>

<script>
    layui.use(['element', 'code', 'form', 'jquery'], function () {
        var form = layui.form;
        var layer = layui.layer;
        //监听提交
        form.on('submit(login)', function (data) {
            //登录
            //调用后台登录验证的方法
            var xmlhttp;
            if (window.XMLHttpRequest) {
                //  IE7+, Firefox, Chrome, Opera, Safari 浏览器执行代码
                xmlhttp = new XMLHttpRequest();
            } else {
                // IE6, IE5 浏览器执行代码
                xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
            }

            var username = data.field.username;
            var password = data.field.password;

            xmlhttp.onreadystatechange = state_Change;
            xmlhttp.open("POST", "/login", true);
            xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
            xmlhttp.send("username=" + username + "&password=" + password);

            function state_Change() {
                if (xmlhttp.readyState == 4) {// 4 = "loaded"
                    if (xmlhttp.status == 200) {// 200 = "OK"
                        var result = JSON.parse(xmlhttp.response);
                        //输出弹窗 重定向到个人中心
                        layer.open({
                            title: result.Title
                            , content: result.Msg,
                            yes: function (index) {
                                if (result.Error == 0) {
                                    window.location.href = "/admin";
                                    layer.close(index); //如果设定了yes回调，需进行手工关闭
                                } else {
                                    layer.close(index); //如果设定了yes回调，需进行手工关闭
                                }
                            }
                        });
                    } else {
                        layer.open({
                            title: '服务器无响应'
                            , content: "服务器开小差啦！！"
                        });
                    }
                }
            }

            return false;
        })
    });
</script>

</body>
</html>